<template>
	<view class="container">
		<scroll-view class="list-content" scroll-y>
			<view v-for="(item, index) in listData" :key="index" class="list-item">
				<image class="item-product-avatar" :src="item.shop_url"></image>
				<view class="item-info">
					<text class="item-product-name">{{item.shop_name}}</text>
					<view class="item-user-wrapper">
						<image class="item-user-avatar" :src="item.user_url"></image>
						<text class="item-user-name">{{item.user_name}}</text>
					</view>
					<text class="item-time">兑换时间：{{timeLoad(item.create_time)}}</text>
				</view>
				<text class="item-score">-{{item.shop_score}}</text>
			</view>
		</scroll-view>
	</view>
		<uni-load-more :status="status" :content-text="contentText" @clickLoadMore="onLoadList()" />
</template>

<script>
	import {
		publicExchangeList
	} from '@/api/api.js'
	import {
		formatDate
	} from '@/utils/time.js'
	import store from '@/store/index.js'; //需要引入store
	export default {
		data() {
			return {
				listData: [],
					status: 'more',
					contentText: {
						contentdown: '点击查看更多',
					},
				listReq: {
					pageInfo: {
						page: 1,
						size: 5
					}
				}
			};
		},
		onLoad() {
			this.loadList()
		},
		methods: {
			onLoadList() {
				this.status = 'loading'
				this.listReq.pageInfo.page += 1
				this.loadList()
			},
			loadList() {
				publicExchangeList(this.listReq).then(res => {
					console.log(res.data)
					if (res.data.code != 0) {
						this.listReq.pageInfo.page -= 1
						this.status = 'noMore'
						uni.showToast({
							icon: "none",
							title: res.data.message
						})
					} else {
						var data = res.data.data
						let list = this.listData
						this.listData = list.concat(data.list)
						if (data.page_info.total_page - this.listReq.pageInfo.page <= 0) {
							this.status = 'noMore'
						} else {
							this.status = 'more'
						}
					}
				})
			},
			timeLoad(time) {
				const d = new Date(time * 1000)
				return formatDate(d, 'yyyy-MM-dd')
			},
		}
	};
</script>

<style scoped>
	.container {
		padding: 20px;
	}

	.list-content {
		height: 100%;
	}

	.list-item {
		display: flex;
		align-items: flex-start;
		margin-bottom: 20px;
	}

	.item-product-avatar {
		width: 80px;
		height: 80px;
		object-fit: cover;
		margin-right: 20px;
	}

	.item-info {
		flex: 1;
		display: flex;
		flex-direction: column;
		justify-content: flex-start;
	}

	.item-product-name {
		font-size: 18px;
		font-weight: bold;
	}

	.item-user-wrapper {
		display: flex;
		align-items: center;
		margin-top: 10px;
	}

	.item-user-avatar {
		width: 40px;
		height: 40px;
		border-radius: 50%;
		overflow: hidden;
		margin-right: 10px;
	}

	.item-user-name {
		font-size: 14px;
	}

	.item-time {
		margin-top: 10px;
		font-size: 12px;
		color: #999;
	}

	.item-score {

		top: 0;
		right: 0;
		font-size: 16px;
		font-weight: bold;
	}
</style>